package com.xzcf.service;

import com.xzcf.entity.*;

import java.util.ArrayList;
import java.util.List;
import java.util.List;
public class UserService {
	private UserDAO userDAO;

	public UserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}
	
	public boolean checkLogin(String userName,String userPwd){
		User user = userDAO.findById(userName);
//		List<User> pwdList = userDAO.findByUserName(userName);
		if(user == null || userPwd == null)return false;
		return user.getUesrPsw().equals(userPwd);
	}
	public boolean saveUser(User user){
		User tmp = null;
		tmp = userDAO.findById(user.getUserName());
		if(tmp != null)return false;
		userDAO.save(user);
		return true;
	}
	public void updateUserInfo(User user){
		userDAO.attachDirty(user);
	}
	public User getUserEntity(String userName){
		return userDAO.findById(userName);
	}
	public List getUserEntityByName(String userName){
		List foo = new ArrayList();
		foo.add(userDAO.findById(userName));
		return foo;
	}
	public List getUserEntityByRealname(String realname){
		return userDAO.findByUserRealname(realname);
	}
	public List getUserEntityByEmail(String email){
		return userDAO.findByUserEmail(email);
	}
	public List getUserList(){
		return userDAO.findAll();
	}
	public void removeUser(String userName){
		User foo = getUserEntity(userName);
		userDAO.delete(foo);
	}
}
